package com.lecyon.farm.controller;


import com.lecyon.farm.base.BaseRequestVo;
import com.lecyon.farm.base.BaseResponse;
import com.lecyon.farm.base.RestResponse;
import com.lecyon.farm.entity.SysAreaData;
import com.lecyon.farm.service.ISysAreaDataService;
import com.lecyon.farm.util.ResultUtil;
import com.lecyon.farm.vo.add.AddSysAreaDataVo;
import com.lecyon.farm.vo.copy.DuplicateVo;
import com.lecyon.farm.vo.modify.ModifySysAreaDataVo;
import com.lecyon.farm.vo.query.QuerySysAreaDataVo;
import com.lecyon.farm.vo.request.IdsVo;
import com.lecyon.farm.vo.view.SysAreaDataVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 全国各地经纬度信息 Controller
 *
 * @author YaoZheng
 * @since 2020-04-22
 */
@RestController
@RequestMapping("/sys-area-data")
@Api(tags = "全国各地经纬度信息")
@ResponseBody
@CrossOrigin
public class SysAreaDataController {

    private ISysAreaDataService sysAreaDataService;

    @Autowired
    public SysAreaDataController(ISysAreaDataService sysAreaDataService) {
        this.sysAreaDataService = sysAreaDataService;
    }

    @ApiOperation(value = "新增经纬度信息", notes = "新增经纬度信息，author:YaoZheng")
    @PostMapping(value = "/post")
    public RestResponse<Long> add(@RequestBody @Valid AddSysAreaDataVo vo) {
        return sysAreaDataService.add(vo);
    }

    @ApiOperation(value = "复制经纬度信息", notes = "复制经纬度信息，author:YaoZheng")
    @PostMapping(value = "/duplicate")
    public RestResponse<Long> duplicate(@RequestBody @Valid DuplicateVo vo) {
        return sysAreaDataService.duplicate(vo);
    }

    @ApiOperation(value = "编辑经纬度信息", notes = "编辑经纬度信息，author:YaoZheng")
    @PostMapping(value = "/put")
    public RestResponse<Long> modify(@RequestBody @Valid ModifySysAreaDataVo vo) {
        return sysAreaDataService.modify(vo);
    }

    @ApiOperation(value = "删除经纬度信息", notes = "删除经纬度信息(支持批量删除)，author:YaoZheng")
    @PostMapping(value = "/remove")
    public BaseResponse remove(@RequestBody @Valid IdsVo vo) {
        return sysAreaDataService.delete(vo);
    }

    @ApiOperation(value = "查看经纬度信息", notes = "查看经纬度信息，author:YaoZheng")
    @PostMapping(value = "/get")
    public RestResponse<SysAreaDataVo> get(@RequestBody @Valid BaseRequestVo<QuerySysAreaDataVo> vo) {
        QuerySysAreaDataVo condition = vo.getEntity(QuerySysAreaDataVo.class);
        condition.setUserToken(vo.getUserToken());
        return sysAreaDataService.get(condition);
    }

    @ApiOperation(value = "查看经纬度信息", notes = "查看经纬度信息，author:YaoZheng")
    @PostMapping(value = "/getByMergerName")
    public RestResponse<SysAreaDataVo> getByMergerName(@RequestBody @Valid BaseRequestVo<QuerySysAreaDataVo> vo) {
        QuerySysAreaDataVo queryEntity = vo.getEntity(QuerySysAreaDataVo.class);
        String condition = queryEntity.getMergerName();
        SysAreaData resultVo = sysAreaDataService.getByMergerName(condition);
        SysAreaDataVo result = new SysAreaDataVo();
        BeanUtils.copyProperties(resultVo, result);
        return ResultUtil.success(null, result);
    }


//    @ApiOperation(value = "查询经纬度信息列表", notes = "查询经纬度信息列表(分页)，author:YaoZheng")
//    @PostMapping(value = "/getList")
//    public RestResponse<Page<SysAreaDataVo>> getPageList(@RequestBody @Valid BaseRequestPageVo<QuerySysAreaDataVo> vo) {
//        return sysAreaDataService.getPageList(vo);
//    }

    @ApiOperation(value = "查询经纬度信息下拉列表", notes = "查询经纬度信息列表(不分页)，author:YaoZheng")
    @PostMapping(value = "/getPullDownList")
    public RestResponse<List<SysAreaDataVo>> getList(@RequestBody @Valid BaseRequestVo<QuerySysAreaDataVo> vo) {
        return sysAreaDataService.getList(vo);
    }

    @ApiOperation(value = "导出查询经纬度信息列表", notes = "导出查询经纬度信息列表，author:YaoZheng")
    @PostMapping(value = "/exportList")
    public RestResponse<String> exportList(@RequestBody @Valid BaseRequestVo<QuerySysAreaDataVo> vo) {
        return sysAreaDataService.exportExcel(vo);
    }
}
